package qc.module.qms.dps.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.module.qms.entity.QmsRawdataMapStation;
import qc.module.qms.entity.QmsRawdataMapTable;
import qc.module.qms.service.QmsBasicConfigCacheGetService;
import qc.module.qms.service.rawdata.QmsRawDataMapGetService;
import qc.module.qms.service.rawdata.QmsRawDataMapStationService;
import qc.module.qms.service.rawdata.QmsRawDataMapTableService;

import java.util.List;

/**
 * DPS中缓存相关controller，控制缓存的更新和过期操作
 * 用作被外部调用进行缓存的过期（更新）、调试或测试获取当前缓存信息
 *
 * @author QuCheng Tech
 * @since 2025/9/2
 */
@RestController
@RequestMapping("/cache")
public class QmsCacheController {
    private static final Logger logger = LoggerFactory.getLogger(QmsCacheController.class);
    @Autowired
    private QmsBasicConfigCacheGetService basicConfigCacheGetService;

    @Autowired
    private QmsRawDataMapTableService rawdataMapTableService;

    @Autowired
    private QmsRawDataMapGetService rawDataMapGetService;

    @Autowired
    private QmsRawDataMapStationService rawdataMapStationService;
    @GetMapping("/rawdatamaptables")
    public List<QmsRawdataMapTable> getRawDataMapTables() {
        logger.info("getRawDataMapTables");

        return rawdataMapTableService.getAllWithCache();
    }
    @PutMapping("/rawdatamaptables")
    public List<QmsRawdataMapTable> putRawDataMapTables() {
        logger.info("putRawDataMapTables");

        return rawdataMapTableService.cachePut();
    }

    @DeleteMapping("/rawdatamaptables")
    public String evictRawDataMapTables() {
        logger.info("evictRawDataMapTables");

        return rawdataMapTableService.cacheEvict();
    }
    @GetMapping("/rawdatamapstations")
    public QmsRawdataMapStation getRawDataMapStationsByParam(@RequestParam String tbcode, String stcd) {
        logger.info("getRawDataMapStationsByParam");

        return getRawDataMapStations(tbcode, stcd);
    }
    public QmsRawdataMapStation getRawDataMapStations(String tbcode, String stcd) {
        logger.info("getRawDataMapStations");

        return rawDataMapGetService.getRawDataMapStationByRawStcd(tbcode, stcd);
    }
}
